﻿using Orchard.Mvc.Routes;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;

namespace NineSeas
{
    public class Routes : IRouteProvider 
    {
        public void GetRoutes(ICollection<RouteDescriptor> routes)
        {
            foreach (var routeDescriptor in GetRoutes())
                routes.Add(routeDescriptor);
        }

        public IEnumerable<RouteDescriptor> GetRoutes()
        {
            return new[] {
                
                new RouteDescriptor {
                    Priority = 11,
                    Route = new Route(
                        "Home",
                        new RouteValueDictionary {
                            {"area", "NineSeas"},
                            {"controller", "Home"},
                            {"action", "Index"}
                        },
                        new RouteValueDictionary(),
                        new RouteValueDictionary {
                            {"area", "NineSeas"}
                        },
                        new MvcRouteHandler())
                },

                new RouteDescriptor {
                    Priority = 11,
                    Route = new Route(
                        "Books/{category}",
                        new RouteValueDictionary {
                            {"area", "NineSeas"},
                            {"controller", "BookView"},
                            {"action", "List"}
                        },
                        new RouteValueDictionary(),
                        new RouteValueDictionary {
                            {"area", "NineSeas"}
                        },
                        new MvcRouteHandler())
                },

                new RouteDescriptor {
                    Priority = 11,
                    Route = new Route(
                        "Books",
                        new RouteValueDictionary {
                            {"area", "NineSeas"},
                            {"controller", "BookView"},
                            {"action", "List"}
                        },
                        new RouteValueDictionary(),
                        new RouteValueDictionary {
                            {"area", "NineSeas"}
                        },
                        new MvcRouteHandler())
                },
                
                new RouteDescriptor {
                    Priority = 12,
                    Route = new Route(
                        "Book/{name}",
                        new RouteValueDictionary {
                            {"area", "NineSeas"},
                            {"controller", "BookView"},
                            {"action", "Index"}
                        },
                        new RouteValueDictionary(),
                        new RouteValueDictionary {
                            {"area", "NineSeas"}
                        },
                        new MvcRouteHandler())
                },
                
                new RouteDescriptor {
                    Priority = 11,
                    Route = new Route(
                        "Book/{name}/Toc/{pageIndex}/{pageSize}",
                        new RouteValueDictionary {
                            {"area", "NineSeas"},
                            {"controller", "BookView"},
                            {"action", "Toc"},
                            {"pageIndex", "0"},
                            {"pageSize", "50"}
                        },
                        new RouteValueDictionary(),
                        new RouteValueDictionary {
                            {"area", "NineSeas"}
                        },
                        new MvcRouteHandler())
                },
                
                new RouteDescriptor {
                    Priority = 11,
                    Route = new Route(
                        "Book/{name}/Chapter/{chapterIndex}",
                        new RouteValueDictionary {
                            {"area", "NineSeas"},
                            {"controller", "BookView"},
                            {"action", "Chapter"},
                            {"chapterIndex", "0"}
                        },
                        new RouteValueDictionary(),
                        new RouteValueDictionary {
                            {"area", "NineSeas"}
                        },
                        new MvcRouteHandler())
                },
                
                new RouteDescriptor {
                    Priority = 11,
                    Route = new Route(
                        "Book/{name}/{action}",
                        new RouteValueDictionary {
                            {"area", "NineSeas"},
                            {"controller", "BookView"},
                            {"action", "{action}"}
                        },
                        new RouteValueDictionary(),
                        new RouteValueDictionary {
                            {"area", "NineSeas"}
                        },
                        new MvcRouteHandler())
                },
                
                new RouteDescriptor {
                    Priority = 11,
                    Route = new Route(
                        "Authoring/Upload/{action}",
                        new RouteValueDictionary {
                            {"area", "NineSeas"},
                            {"controller", "Upload"},
                            {"action", "BookImage"}
                        },
                        new RouteValueDictionary(),
                        new RouteValueDictionary {
                            {"area", "NineSeas"}
                        },
                        new MvcRouteHandler())
                },
                // 
                new RouteDescriptor {
                    Priority = 11,
                    Route = new Route(
                        "Authoring",
                        new RouteValueDictionary {
                            {"area", "NineSeas"},
                            {"controller", "Authoring"},
                            {"action", "Index"}
                        },
                        new RouteValueDictionary(),
                        new RouteValueDictionary {
                            {"area", "NineSeas"}
                        },
                        new MvcRouteHandler())
                },
                new RouteDescriptor {
                    Priority = 11,
                    Route = new Route(
                        "Authoring/Statistics",
                        new RouteValueDictionary {
                            {"area", "NineSeas"},
                            {"controller", "Authoring"},
                            {"action", "Statistics"}
                        },
                        new RouteValueDictionary(),
                        new RouteValueDictionary {
                            {"area", "NineSeas"}
                        },
                        new MvcRouteHandler())
                },

                // actions against Chapters
                new RouteDescriptor {
                    Priority = 12,
                    Route = new Route(
                        "Authoring/Books/Book/{bookId}/Chapters",
                        new RouteValueDictionary {
                            {"area", "NineSeas"},
                            {"controller", "Chapter"},
                            {"action", "Index"}
                        },
                        new RouteValueDictionary(),
                        new RouteValueDictionary {
                            {"area", "NineSeas"}
                        },
                        new MvcRouteHandler())
                },
                new RouteDescriptor {
                    Priority = 13,
                    Route = new Route(
                        "Authoring/Books/Book/{bookId}/Chapter/Create",
                        new RouteValueDictionary {
                            {"area", "NineSeas"},
                            {"controller", "Chapter"},
                            {"action", "Create"}
                        },
                        new RouteValueDictionary(),
                        new RouteValueDictionary {
                            {"area", "NineSeas"}
                        },
                        new MvcRouteHandler())
                },
                new RouteDescriptor {
                    Priority = 12,
                    Route = new Route(
                        "Authoring/Books/Book/{bookId}/Chapter/{id}/{action}",
                        new RouteValueDictionary {
                            {"area", "NineSeas"},
                            {"controller", "Chapter"},
                            {"action", "Edit"}
                        },
                        new RouteValueDictionary(),
                        new RouteValueDictionary {
                            {"area", "NineSeas"}
                        },
                        new MvcRouteHandler())
                },

                // actions against books
                new RouteDescriptor {
                    Priority = 11,
                    Route = new Route(
                        "Authoring/Books",
                        new RouteValueDictionary {
                            {"area", "NineSeas"},
                            {"controller", "Books"},
                            {"action", "Index"}
                        },
                        new RouteValueDictionary(),
                        new RouteValueDictionary {
                            {"area", "NineSeas"}
                        },
                        new MvcRouteHandler())
                },
                new RouteDescriptor {
                    Priority = 11,
                    Route = new Route(
                        "Authoring/Books/Book/{id}/{action}",
                        new RouteValueDictionary {
                            {"area", "NineSeas"},
                            {"controller", "Books"},
                            {"action", "Edit"},
                            {"id", "-1"}
                        },
                        new RouteValueDictionary(),
                        new RouteValueDictionary {
                            {"area", "NineSeas"}
                        },
                        new MvcRouteHandler())
                },
                new RouteDescriptor {
                    Priority = 11,
                    Route = new Route(
                        "Authoring/Books/Book/Edit",
                        new RouteValueDictionary {
                            {"area", "NineSeas"},
                            {"controller", "Books"},
                            {"action", "Edit"}
                        },
                        new RouteValueDictionary(),
                        new RouteValueDictionary {
                            {"area", "NineSeas"}
                        },
                        new MvcRouteHandler())
                },         

                // actions against Author Profile
                new RouteDescriptor {
                    Priority = 11,
                    Route = new Route(
                        "Authoring/EditProfile",
                        new RouteValueDictionary {
                            {"area", "NineSeas"},
                            {"controller", "AuthorProfile"},
                            {"action", "EditProfile"}
                        },
                        new RouteValueDictionary(),
                        new RouteValueDictionary {
                            {"area", "NineSeas"}
                        },
                        new MvcRouteHandler())
                },
                new RouteDescriptor {
                    Priority = 11,
                    Route = new Route(
                        "Authoring/Ads",
                        new RouteValueDictionary {
                            {"area", "NineSeas"},
                            {"controller", "Authoring"},
                            {"action", "Ads"}
                        },
                        new RouteValueDictionary(),
                        new RouteValueDictionary {
                            {"area", "NineSeas"}
                        },
                        new MvcRouteHandler())
                },

                // authors view
                new RouteDescriptor {
                    Priority = 11,
                    Route = new Route(
                        "Authors",
                        new RouteValueDictionary {
                            {"area", "NineSeas"},
                            {"controller", "Authors"},
                            {"action", "Index"}
                        },
                        new RouteValueDictionary(),
                        new RouteValueDictionary {
                            {"area", "NineSeas"}
                        },
                        new MvcRouteHandler())
                },

                
                // authors view
                
                new RouteDescriptor {
                    Priority = 11,
                    Route = new Route(
                        "Author/{name}/{pageIndex}/{pageSize}",
                        new RouteValueDictionary {
                            {"area", "NineSeas"},
                            {"controller", "Author"},
                            {"action", "Index"},
                            {"pageIndex", UrlParameter.Optional},
                            {"pageSize", UrlParameter.Optional}
                        },
                        new RouteValueDictionary(),
                        new RouteValueDictionary {
                            {"area", "NineSeas"}
                        },
                        new MvcRouteHandler())
                },
                new RouteDescriptor {
                    Priority = 11,
                    Route = new Route(
                        "Authors/Author/{id}/Details/{pageIndex}/{pageSize}",
                        new RouteValueDictionary {
                            {"area", "NineSeas"},
                            {"controller", "Authors"},
                            {"action", "Details"},
                            {"pageIndex", UrlParameter.Optional},
                            {"pageSize", UrlParameter.Optional}
                        },
                        new RouteValueDictionary(),
                        new RouteValueDictionary {
                            {"area", "NineSeas"}
                        },
                        new MvcRouteHandler())
                },

                // authors view
                new RouteDescriptor {
                    Priority = 11,
                    Route = new Route(
                        "Authors/Author/{id}/Details",
                        new RouteValueDictionary {
                            {"area", "NineSeas"},
                            {"controller", "Authors"},
                            {"action", "Details"}
                        },
                        new RouteValueDictionary(),
                        new RouteValueDictionary {
                            {"area", "NineSeas"}
                        },
                        new MvcRouteHandler())
                }
            };
        }
    }
}